﻿using Microsoft.Xna.Framework.Input;

namespace BlawkayEngine.Input
{
    public class KeyboardInput
    {
        KeyboardState _PrevState;
        KeyboardState _CurrState;

        public KeyboardInput()
        {
            _PrevState = Keyboard.GetState();
            _CurrState = Keyboard.GetState();
        }

        public void Update()
        {
            _PrevState = _CurrState;
            _CurrState = Keyboard.GetState();
        }

        /// <summary>
        /// Detertines if one of keys inputed have just been pressed
        /// </summary>
        /// <param name="oKeys">Keys to Check</param>
        /// <returns>True if a key has just been pressed</returns>
        public bool JustPressed(params Keys[] oKeys)
        {
            foreach (Keys key in oKeys)
            {
                bool keyUp = _PrevState.IsKeyUp(key);
                bool keyDown = _CurrState.IsKeyDown(key);

                if (keyUp && keyDown)
                    return true;
            }

            return false;
        }

        /// <summary>
        /// Detertines if one of keys inputed have just been released
        /// </summary>
        /// <param name="oKeys">Keys to Check</param>
        /// <returns>True if a key has just been released</returns>
        public bool JustReleased(params Keys[] oKeys)
        {
            foreach (Keys key in oKeys)
            {
                bool keyDown = _PrevState.IsKeyDown(key);
                bool keyUp = _CurrState.IsKeyUp(key);

                if (keyDown && keyUp)
                    return true;
            }

            return false;
        }

        /// <summary>
        /// Detertines if all of keys inputed are being pressed
        /// </summary>
        /// <param name="oKeys">Keys to Check</param>
        /// <returns>True if all the keys are being pressed</returns>
        public bool IsPressed(params Keys[] oKeys)
        {
            foreach (Keys key in oKeys)
            {
                bool keyDown = _CurrState.IsKeyDown(key);

                if (keyDown == false)
                    return false;
            }

            return true;
        }

        /// <summary>
        /// Detertines if all of keys inputed are being released
        /// </summary>
        /// <param name="oKeys">Keys to Check</param>
        /// <returns>True if all the keys are being released</returns>
        public bool IsReleased(params Keys[] oKeys)
        {
            foreach (Keys key in oKeys)
            {
                bool keyUp = _CurrState.IsKeyUp(key);

                if (keyUp == false)
                    return false;
            }

            return true;
        }

        /// <summary>
        /// Detertines if one of keys inputed is pressed
        /// </summary>
        /// <param name="oKeys">Keys to Check</param>
        /// <returns>True if one of the keys is pressed</returns>
        public bool IsOnePressed(params Keys[] oKeys)
        {
            foreach (Keys key in oKeys)
            {
                bool keyDown = _CurrState.IsKeyDown(key);

                if (keyDown)
                    return true;
            }

            return false;
        }

        /// <summary>
        /// Detertines if one of keys inputed is released
        /// </summary>
        /// <param name="oKeys">Keys to Check</param>
        /// <returns>True if one of the keys is released</returns>
        public bool IsOneReleased(params Keys[] oKeys)
        {
            foreach (Keys key in oKeys)
            {
                bool keyUp = _CurrState.IsKeyUp(key);

                if (keyUp)
                    return true;
            }

            return false;
        }

    }
}
